package com.ssy.lingxi.system.controller;

import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.system.dto.request.*;
import com.ssy.lingxi.system.entity.MemberConfig;
import com.ssy.lingxi.system.model.request.IdVO;
import com.ssy.lingxi.system.model.request.MemberConfigAddVO;
import com.ssy.lingxi.system.model.request.MemberConfigUpdateVO;
import com.ssy.lingxi.system.model.response.MemberConfigGetVO;
import com.ssy.lingxi.system.model.response.MemberConfigTagVO;
import com.ssy.lingxi.system.service.MemberConfigService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;
/**
 * @menu 会员角色权限管理-会员注册资料设置
 * @author wrc
 * @date 2020/7/20
 */
@Api(tags = "会员字段配置管理")
@RestController
public class MemberConfigController {
    @Resource
    MemberConfigService memberConfigService;

    @ApiOperation(value = " 查询会员字段配置列表")
    @GetMapping("/member/list")
    public Wrapper<PageData<MemberConfig>> memberList(MemberListRequest request) {
        return memberConfigService.memberList(request);
    }

    /**
    * 根据角色ID查询会员字段配置列表
    */
    @GetMapping("/member/by/roleid/list")
    public Wrapper<List<MemberConfig>> memberByRoleIdList(MemberByRoleIdListRequest request) {
        return memberConfigService.memberByRoleIdList(request);
    }

    /**
     * 设置新增修改删除角色关联的会员配置资料
     */
    @ApiOperation(value = "设置新增修改删除角色关联的会员配置资料")
    @PostMapping("/member/set/role/config")
    public Wrapper<Void> setRoleConfig(@Valid @RequestBody SetRoleConfigRequest request) {
        return memberConfigService.setRoleConfig(request);
    }

    @ApiOperation(value = "查询会员注册字段标签列表")
    @GetMapping("/member/tag/get")
    public Wrapper<List<MemberConfigTagVO>> getMemberConfigTagList() {
        return memberConfigService.getMemberConfigTagList();
    }

    /**
     * 查询会员注册资料校验规则列表
     * @return 查询结果
     */
    @ApiOperation(value = "查询会员注册字段校验规则列表")
    @GetMapping("/member/checkrule/get")
    public Wrapper<List<MemberConfigTagVO>> getMemberConfigCheckRuleList() {
        return memberConfigService.getMemberConfigCheckRuleList();
    }

    @ApiOperation(value = "新增会员注册字段配置信息")
    @PostMapping("/member/add")
    public Wrapper<Void> addMember(@Valid  @RequestBody MemberConfigAddVO configVO, HttpServletRequest httpServletRequest) {
        return memberConfigService.addMember(configVO,httpServletRequest);
    }

    @ApiOperation(value = "修改会员注册字段配置信息")
    @PostMapping("/member/update")
    public Wrapper<Void> updateMember(@Valid @RequestBody MemberConfigUpdateVO updateVO) {
        return memberConfigService.updateMember(updateVO);
    }

    @ApiOperation(value = "查询会员注册字段配置信息")
    @GetMapping("/member/get")
    public Wrapper<MemberConfigGetVO> getMemberConfig(@Valid IdVO idVO) {
        return memberConfigService.getMemberConfig(idVO);
    }

    @ApiOperation(value = "删除会员注册字段配置信息")
    @PostMapping("/member/delete")
    public Wrapper<Void> deleteMember(@Valid @RequestBody DeleteMemberConfigRequest request) {
        return memberConfigService.deleteMember(request);
    }

    @ApiOperation(value = "启用停用会员注册字段配置信息")
    @PostMapping("/member/start/stop")
    public Wrapper<Void> startRoStopMember(@Valid @RequestBody StartRoStopMemberRequest request) {
        return memberConfigService.startRoStopMember(request);
    }
}
